<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<!-- TODO: refactor form styles and js -->
<div class="fade backup-dialog" id="rollback-warning" style="display: none;">
    <div class="popup popup-notice">
        <div class="popup-inner">
            <header class="popup-header">
                <h2 class="popup-title"><?php echo __('Warning') ?></h2>
            </header>
            <div class="popup-content">
                <p class="message-text"><?php echo __('Any data created since the backup was made will be lost including admin users, customers and orders.')?></p>
                <p class="message-text"><?php echo __('Are you sure you want to proceed?')?></p>
                <button type="button" onclick="backup.requestPassword()"><?php echo __('OK')?></button>
                <button type="button" onclick="backup.hidePopups()"><?php echo __('Cancel')?></button>
            </div>
        </div>
    </div>
</div>

<div class="fade backup-dialog" id="backup-warning" style="display: none;">
    <div class="popup popup-notice">
        <div class="popup-inner">
            <header class="popup-header">
                <h2 class="popup-title"><?php echo __('Warning') ?></h2>
            </header>
            <div class="popup-content">
                <p class="message-text">
                    <?php echo __("It will take time to create a backup.")?><br>
                    <?php echo __('Please wait until the action ends.')?><br>
                    <?php echo __('Are you sure you want to continue?')?>
                </p>
                <button type="button" onclick="backup.requestBackupOptions()"><?php echo __('OK')?></button>
                <button type="button" onclick="backup.hidePopups()"><?php echo __('Cancel')?></button>
            </div>
        </div>
    </div>
</div>

<div class="fade backup-dialog" id="backup-options" style="display: none;">
    <div class="popup popup-notice">
        <div class="popup-inner">
            <header class="popup-header">
                <h2 class="popup-title"><?php echo __('Backup options') ?></h2>
            </header>
            <div class="popup-content">
                <div class="backup-messages" style="display: none;"><div class="messages"></div></div>
                <p class="message-text"><?php echo __('Please specify backup creation option.')?></p>
                <form action="" method="post" id="backup-form">
                    <div class="form-list question">

                        <label for="backup_name" class="nobr"><?php echo __('Backup Name')?></label>
                        <input type="text" name="backup_name" id="backup_name" class="required-entry validate-alphanum-with-spaces validate-length maximum-length-50" maxlength="50" />
                        <div class="note"><?php echo __('Please use only letters (a-z or A-Z), numbers (0-9) or spaces in this field.'); ?></div>

                        <div class="maintenance-checkbox-container">
                            <input type="checkbox" name="maintenance_mode" value="1" id="backup_maintenance_mode"/>
                            <label for="backup_maintenance_mode"><?php echo __('Please put your store into maintenance mode during backup.')?></label>
                        </div>

                        <div id="exclude-media-checkbox-container" style="display: none;">
                            <input type="checkbox" name="exclude_media" value="1" id="exclude_media"/>
                            <label for="exclude_media"><?php echo __('Exclude media folder from backup')?></label>
                        </div>
                    </div>
                </form>

                <button type="button" data-mage-init='{"button":{"event":"submit","target":"#backup-form"}}'><?php echo __('OK')?></button>
                <button type="button" onclick="backup.hidePopups()"><?php echo __('Cancel')?></button>
            </div>
        </div>
    </div>
 </div>

<div class="fade backup-dialog" id="rollback-request-password" style="display: none;">
    <div class="popup popup-notice">
        <div class="popup-inner">
            <header class="popup-header">
                <h2 class="popup-title"><?php echo __('Please enter a password.') ?></h2>
            </header>
            <div class="popup-content">
                <div class="backup-messages" style="display: none;"><div class="messages"></div></div>
                <p class="message-text">
                    <?php echo __('Please enter the password to confirm rollback.')?><br>
                    <?php echo __('This action cannot be undone.')?>
                </p>
                <p class="message-text"><?php echo __('Are you sure you want to proceed?')?></p>
                <form action="" method="post" id="rollback-form">
                    <div class="password-box-container">

                        <label for="password" class="nobr"><?php echo __('User Password')?> <span class="required">*</span></label>
                        <input type="password" name="password" id="password" class="required-entry">

                        <div class="maintenance-checkbox-container">
                            <input type="checkbox" name="maintenance_mode" value="1" id="rollback_maintenance_mode"/>
                            <label for="rollback_maintenance_mode"><?php echo __('Please put your store into maintenance mode during rollback processing.')?></label>
                        </div>

                        <div id="use-ftp-checkbox-row" style="display: none;">
                            <input type="checkbox" name="use_ftp" value="1" id="use_ftp" onClick="backup.toggleFtpCredentialsForm();"/> <label for="use_ftp"><?php echo __('Use FTP Connection')?></label>
                        </div>
                    </div>
                    <div class="entry-edit" id="ftp-credentials-container" style="display: none;">
                        <h4><?php echo __('FTP credentials')?></h4>
                        <fieldset>
                            <label for="ftp_host"><?php echo __('FTP Host')?> <span class="required">*</span></label>
                            <input type="text" name="ftp_host" id="ftp_host">
                            <br>
                            <label for="ftp_user"><?php echo __('FTP Login')?> <span class="required">*</span></label>
                            <input type="text" name="ftp_user" id="ftp_user">
                            <br>
                            <label for="ftp_pass"><?php echo __('FTP Password')?> <span class="required">*</span></label>
                            <input type="password" name="ftp_pass" id="ftp_pass">
                            <br>
                            <label for="ftp_path"><?php echo __('Magento root directory')?></label>
                            <input type="text" name="ftp_path" id="ftp_path">
                        </fieldset>
                    </div>
                </form>

                <button type="button" data-mage-init='{"button":{"event":"submit","target":"#rollback-form"}}'><?php echo __('OK')?></button>
                <button type="button" onclick="backup.hidePopups()"><?php echo __('Cancel')?></button>
            </div>
        </div>
    </div>
</div>

<?php
    $rollbackUrl = $this->getUrl('*/*/rollback');
    $backupUrl = $this->getUrl('*/*/create');
?>

<script type="text/javascript">
require([
    "prototype",
    "mage/adminhtml/backup"
], function(){

//<![CDATA[
    backup = new AdminBackup();
    backup.rollbackUrl = '<?php echo $this->escapeJsQuote($rollbackUrl);?>';
    backup.backupUrl = '<?php echo $this->escapeJsQuote($backupUrl);?>';
//]]>

});
</script>
